package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.IDispatchEngineeringOrderListView;
import com.cloudsigns.factorymanager2.engineering.IView.IReceiveEngineeringOrderListView;
import com.cloudsigns.factorymanager2.engineering.bean.OrderParentBean;
import com.cloudsigns.factorymanager2.engineering.model.DispatchEngineeringOrderListModel;
import com.cloudsigns.factorymanager2.engineering.model.IDispatchEngineeringOrderListModel;
import com.cloudsigns.factorymanager2.engineering.model.IReceiveEngineeringOrderListModel;
import com.cloudsigns.factorymanager2.engineering.model.ReceiveEngineeringOrderListModel;

import java.util.List;

/**
 * Created by tony on 2018/3/23.
 */

public class DispatchEngineeringOrderListPresenter {
    private IDispatchEngineeringOrderListView view;
    private IDispatchEngineeringOrderListModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public DispatchEngineeringOrderListPresenter(IDispatchEngineeringOrderListView view) {
        this.view = view;
        this.model = new DispatchEngineeringOrderListModel();
    }

    public void getEngineeringDispatchOrderList() {
        view.showLoading();

        model.getEngineeringDispatchOrderList(new DispatchEngineeringOrderListModel.OnEngineeringDispatchOrderListListener() {
            @Override
            public void getDataSuccessed(final List<OrderParentBean> engineeringOrderBeanList) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getDataSuccessed(engineeringOrderBeanList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void getDataFailed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }


        });
    }
}
